/**
 * @program: yygh_parent
 * @ClassName EasyExcelWrite
 * @description:
 * @author: zyw
 * @create: 2023-05-19 15:48
 * @Version 1.0
 **/
package com.atguigu.yygh.cmn.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
import com.alibaba.excel.write.metadata.WriteSheet;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class EasyExcelWrite {
    public static void main(String[] args) {
        //方式1
        List<Stu> stu1 = new ArrayList<Stu>();
        for (int i = 0; i < 10; i++) {
            Stu data = new Stu();
            data.setSno(i);
            data.setSname("张三"+i);
            stu1.add(data);
        }
        List<Stu> stu2 = new ArrayList<Stu>();
        for (int i = 0; i < 10; i++) {
            Stu data = new Stu();
            data.setSno(i);
            data.setSname("李四"+i);
            stu2.add(data);
        }
//        EasyExcel.write("C:\\Users\\zeng\\Desktop\\test.xlsx",Stu.class).sheet("学生列表1").doWrite(list);
        //方式2
        ExcelWriter excelWriter = EasyExcel.write("C:\\Users\\zeng\\Desktop\\m2.xlsx", Stu.class).build();
        WriteSheet sheet1 = EasyExcel.writerSheet(0, "学生列表1").build();
        WriteSheet sheet2 = EasyExcel.writerSheet(1, "学生列表2").build();
        excelWriter.write(stu1, sheet1);
        excelWriter.write(stu2, sheet2);
        excelWriter.finish();
    }
}
 
